﻿using System;
using System.Windows.Forms;

namespace Microsoft.Office.OneNote.XmlViewer.Controls
{
    public enum ViewType
    {
        Objects,
        Xml,
        Html,
    }

    public partial class ViewSwitcher : UserControl
    {
        public event EventHandler CurrentViewChanged;

        private ViewType _view;

        public ViewSwitcher()
        {
            InitializeComponent();
        }

        public ViewType CurrentView
        {
            get { return _view; }
            set 
            {
                if (_view != value)
                {
                    _view = value;

                    btnObjects.Checked = (value == ViewType.Objects);
                    btnHTML.Checked = (value == ViewType.Html);
                    btnXml.Checked = (value == ViewType.Xml);

                    OnCurrentViewChanged(EventArgs.Empty);
                }
            }
        }

        protected virtual void OnCurrentViewChanged(EventArgs e)
        {
            if (CurrentViewChanged != null)
            {
                CurrentViewChanged(this, e);
            }
        }

        private void btnObjects_Click(object sender, EventArgs e)
        {
            CurrentView = ViewType.Objects;
        }

        private void btnXml_Click(object sender, EventArgs e)
        {
            CurrentView = ViewType.Xml;
        }

        private void btnHTML_Click(object sender, EventArgs e)
        {
            CurrentView = ViewType.Html;
        }
    }
}
